package com.sqlcheck.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 大模型使用统计实体
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName(value = "llm_usage_statistics")
public class LLMUsageStatistics {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @TableField("user_id")
    private Long userId;

    @TableField("date")
    private LocalDate date;

    @TableField("hour")
    private Integer hour; // 0-23, null表示全天

    @TableField("llm_provider")
    private String llmProvider;

    @TableField("llm_model")
    private String llmModel;

    @TableField("total_requests")
    private Integer totalRequests;

    @TableField("successful_requests")
    private Integer successfulRequests;

    @TableField("failed_requests")
    private Integer failedRequests;

    @TableField("timeout_requests")
    private Integer timeoutRequests;

    @TableField("total_processing_time")
    private Long totalProcessingTime;

    @TableField("avg_processing_time")
    private Integer avgProcessingTime;

    @TableField("max_processing_time")
    private Integer maxProcessingTime;

    @TableField("min_processing_time")
    private Integer minProcessingTime;

    @TableField("total_tokens")
    private Long totalTokens;

    @TableField("estimated_cost")
    private BigDecimal estimatedCost;

    @TableField("avg_confidence_score")
    private BigDecimal avgConfidenceScore;

    @TableField("high_confidence_count")
    private Integer highConfidenceCount;

    @TableField("low_confidence_count")
    private Integer lowConfidenceCount;

    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;

    // Alias methods for compatibility
    public String getProvider() {
        return this.llmProvider;
    }

    public LLMUsageStatistics setProvider(String provider) {
        this.llmProvider = provider;
        return this;
    }

    public String getModelName() {
        return this.llmModel;
    }

    public LLMUsageStatistics setModelName(String modelName) {
        this.llmModel = modelName;
        return this;
    }

    public Integer getRequestCount() {
        return this.totalRequests;
    }

    public LLMUsageStatistics setRequestCount(Integer requestCount) {
        this.totalRequests = requestCount;
        return this;
    }

    public Integer getSuccessCount() {
        return this.successfulRequests;
    }

    public LLMUsageStatistics setSuccessCount(Integer successCount) {
        this.successfulRequests = successCount;
        return this;
    }

    public Integer getFailureCount() {
        return this.failedRequests;
    }

    public LLMUsageStatistics setFailureCount(Integer failureCount) {
        this.failedRequests = failureCount;
        return this;
    }
}